package com.yilin.medical.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yilin.medical.R;
import com.yilin.medical.model.BingLiDetailsBean;
import com.yilin.medical.utils.ToastUntil;

/**
 * 肿瘤adapter
 * 
 * @author lijianqun
 * 
 */
public class BingLiDetailsAdapter extends BaseAdapter {
	private Context context;
	private List<BingLiDetailsBean> list;
	ViewHolder holder = null;

	public BingLiDetailsAdapter(Context context, List<BingLiDetailsBean> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size()+1;
	}

	@Override
	public Object getItem(int position) {
		if (position ==0) {
			return null;
		} else {
			return list.get(position+1);
		}
		
	}

	@Override
	public long getItemId(int position) {
		return position+1;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final BingLiDetailsBean bean;
		View view;
		if (position == 0) {
			view = View.inflate(context, R.layout.binglitaolundetailstop_layout, null);
			return view;
		}
		
		if (convertView != null && convertView instanceof RelativeLayout) {
			holder = (ViewHolder) convertView.getTag();
		} else {
			holder = new ViewHolder();
				convertView = View.inflate(context,
						R.layout.listitem_binglitaolundetails, null);
				holder.iv = (ImageView) convertView.findViewById(R.id.iv);
				holder.tv_name = (TextView) convertView
						.findViewById(R.id.tv_name);
				holder.tv_huifu = (TextView) convertView
						.findViewById(R.id.tv_huifu);
				holder.tv_describe = (TextView) convertView
						.findViewById(R.id.tv_describe);
				holder.rl_pinglun = (RelativeLayout) convertView
						.findViewById(R.id.rl_pinglun);
				holder.rl_fabupinglun = (RelativeLayout) convertView
						.findViewById(R.id.rl_fabupinglun);
				holder.ll_fabupinglun = (LinearLayout) convertView
						.findViewById(R.id.ll_fabupinglun);
				holder.et_content = (EditText) convertView
						.findViewById(R.id.et_content);
				convertView.setTag(holder);

		
		}
		bean = list.get(position-1);
		if (bean.isShowPingLun) {
			holder.ll_fabupinglun.setVisibility(View.VISIBLE);
			holder.rl_pinglun.setVisibility(View.GONE);
		} else {
			holder.rl_pinglun.setVisibility(View.VISIBLE);
			holder.ll_fabupinglun.setVisibility(View.GONE);
		}
		holder.rl_pinglun.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				/*ToastUntil.showShortToast(context, "rl_pinglun点击"
						+ bean.isShowPingLun);*/
				bean.isShowPingLun = true;
				notifyDataSetChanged();
			}
		});
		holder.ll_fabupinglun.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ToastUntil.showShortToast(context, "发布成功!");
				bean.isShowPingLun = false;
				notifyDataSetChanged();
			}
		});
		return convertView;
	}

	class ViewHolder {
		ImageView iv;
		TextView tv_name, tv_date, tv_describe, tv_huifu;
		RelativeLayout rl_pinglun, rl_fabupinglun;
		EditText et_content;
		LinearLayout ll_fabupinglun;
	}

}
